﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 观察者模式
{
    /// <summary>
    /// 通知者接口
    /// </summary>
    interface ISubject
    {
        void Attach(Observer observer);

        void Detach(Observer observer);

        void Notify();

        string SubjectState
        {
            get;
            set;
        }
    }

    class Boss : ISubject
    {
        private IList<Observer> _observers = new List<Observer>();

        private string action;

        public string SubjectState
        {
            get => this.action;
            set => this.action = value;
        }

        public void Attach(Observer observer)
        {
            this._observers.Add(observer);
        }

        public void Detach(Observer observer)
        {
            this._observers.Remove(observer);
        }

        public void Notify()
        {
            foreach (var item in this._observers)
            {
                item.Update();
            }
        }
    }
}
